<template>
  <div>
    <bpm-c-form>
      <bpm-c-block :key="0"
                   :ptitle="inputTitle[0]"
                   :preadonly="inputReadonly[0]"
                   :pinputtype="inputType[0]"
                   :pline="inputLine[0]"
                   v-model="costcenter"
                   @valueChanged="setSelectedGridInfoCellIndex($event,0)"
      />
    </bpm-c-form>
    <bpm-c-form>
      <bpm-c-block :key="1"
                   :ptitle="inputTitle[1]"
                   :preadonly="inputReadonly[1]"
                   :pinputtype="inputType[1]"
                   :pline="inputLine[1]"
                   v-model="selectedGridInfo[gridShowInfo[1]]"
                   :showValue="internalName"
                   @sltvalueChanged="setSelectedGridInfoCellIndex($event,1)"
      />
      <bpm-c-block :key="2"
                   :ptitle="inputTitle[2]"
                   :preadonly="inputReadonly[2]"
                   :pinputtype="inputType[2]"
                   :pline="inputLine[2]"
                   v-model="selectedGridInfo[gridShowInfo[2]]"
                   :showValue="subjectname"
                   @sltvalueChanged="setSelectedGridInfoCellIndex($event,2)"
      />
    </bpm-c-form>
    <bpm-c-form>
      <bpm-c-block :key="3"
                   :ptitle="inputTitle[3]"
                   :preadonly="inputReadonly[3]"
                   :pinputtype="inputType[3]"
                   :pline="inputLine[3]"
                   v-model="selectedGridInfo[gridShowInfo[3]]"
                   :validateExp="validateExp[3]"
                   @valueChanged="setSelectedGridInfoCellIndex($event,3)"
      />
      <bpm-c-block :key="4"
                   :ptitle="inputTitle[4]"
                   :preadonly="inputReadonly[4]"
                   :pinputtype="inputType[4]"
                   :pline="inputLine[4]"
                   v-model="selectedGridInfo[gridShowInfo[4]]"
                   :validateExp="validateExp[4]"
                   @valueChanged="setSelectedGridInfoCellIndex($event,4)"
      />
    </bpm-c-form>
    <bpm-c-form>
      <bpm-c-block :key="5"
                   :ptitle="inputTitle[5]"
                   :preadonly="inputReadonly[5]"
                   :pinputtype="inputType[5]"
                   :pline="inputLine[5]"
                   v-model="selectedGridInfo[gridShowInfo[5]]"
                   @valueChanged="setSelectedGridInfoCellIndex($event,5)"
      />
      <bpm-c-block :key="6"
                   :ptitle="inputTitle[6]"
                   :preadonly="inputReadonly[6]"
                   :pinputtype="inputType[6]"
                   :pline="inputLine[6]"
                   v-model="selectedGridInfo[gridShowInfo[6]]"
                   @valueChanged="setSelectedGridInfoCellIndex($event,6)"
      />
    </bpm-c-form>
    <!--v-model="selectedGridInfo[gridShowInfo[i]]"-->
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'

export default {
  name: 'bpmDFeeChoose',
  props: {
    title: '',
    dialogVisible: {
      type: Number,
      default: -1
    },
    pselectType: {
      type: String,
      default: ''
    },
    validateExp: {
      type: Object,
      default () {
        return {}
      }
    },
    gridStatus: ''
  },
  data () {
    let inputLine = [1, 2, 2, 2, 2, 2, 2]
    let inputType = ['splitcostcenter', 'sltsplitinternalorder', 'sltsplitsubject', 'number', 'number', 'number', 'number']
    let gridShowInfo = ['costcentername', 'internalordercode', 'subjectcode', 'notaxamount', 'tax', 'reimbursesum', 'actualreimbursesum']
    return {
      inputLine: inputLine,
      inputType: inputType,
      gridShowInfo: gridShowInfo
    }
  },
  computed: {
    ...mapState(['ssc', 'chooseDialogEnum', 'pageType', 'pageTypeEnum', 'lang']),
    inputTitle () {
      return [
        this.getLanguage('label.whBtReimburseCostshare.costcentername'),
        this.getLanguage('label.whBtReimburseCostshare.internalordername'),
        this.getLanguage('label.whBtReimburseCostshare.subjectname'),
        this.getLanguage('label.whBtReimburseCostshare.notaxamountCurrency'),
        this.getLanguage('label.whBtReimburseCostshare.tax'),
        this.getLanguage('label.whBtReimburseCostshare.reimbursesum'),
        this.getLanguage('label.whBtReimburseCostshare.actualreimbursesumCurrency')
      ]
    },
    selectedGridInfo () {
      console.log('split info........', this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare)
      return this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare
    },
    reimbursecostcentercode () {
      return this.ssc.reimburse.whBtReimburse.reimbursecostcentercode
    },
    internalName () {
      return this.selectedGridInfo.internalordername
    },
    subjectname () {
      return this.selectedGridInfo.subjectname
    },
    costcenter: {
      get () {
        return JSON.stringify({
          name: this.selectedGridInfo.costcentername,
          value: this.selectedGridInfo.costcentercode
        })
      },
      set (value) {
        let object = JSON.parse(value)
        console.log('costcenter-----------d', object)
        object && this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
          name: 'costcentername',
          value: object.name
        })
        object && this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
          name: 'costcentercode',
          value: object.value
        })
      }
    },
    inputReadonly () {
      switch (this.pageType) {
        case this.pageTypeEnum.draft:
          return [false, false, false, false, false, true, true]
        case this.pageTypeEnum.approve:
          return [false, false, false, false, false, false, false]
        case this.pageTypeEnum.approveFee:
          return [true, true, true, false, false, true, true]
        case this.pageTypeEnum.view:
        default:
          return [true, true, true, true, true, true, true]
      }
    },
    isDialogVisible () {
      return this.dialogVisible >= 0
    },
    reimbursecompanycode () {
      return this.ssc.reimburse.whBtReimburse.reimbursecompanycode
    },
    preInternalorder () {
      return {
        reimbursecompanycode: this.reimbursecompanycode,
        reimbursecostcentercode: this.selectedGridInfo.costcentercode
      }
    },
    preSubject () {
      return {
        reimbursecompanycode: this.reimbursecompanycode,
        reimbursecostcentercode: this.selectedGridInfo.costcentercode,
        inwardOrderCode: this.selectedGridInfo.internalordercode
      }
    }
  },
  watch: {
    radioValue (to) {
      console.log('rebrusechoose value changed......', to)
    }
  },
  methods: {
    ...mapActions(['queryInternalOrder', 'queryBudgetSubject', 'updateDataSscCachePaymentInfo', 'querySplitInternalOrder']),
    addClicked () {
    },
    updateClicked () {},
    deleteClicked () {},
    selectClick (i) {
      console.log(i)
      this.dialogVisible = i
    },
    selDialogClicked (aObj) {
      this.dialogVisible = -1
      console.log('choose', aObj)
    },
    setDialogClose () {
      this.dialogVisible = -1
    },
    setSelectedGridInfoCellIndex (v, index) {
      console.log('======================', v, index)
      if (this.pageType === this.pageTypeEnum.draft) {
        if (index === 0) {
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.internalordercode = ''
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.internalordername = ''
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.subjectcode = ''
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.subjectname = ''
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.notaxamountCurrency = 0
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.taxCurrency = 0
          this.noTaxAmountOnblur()
        } else if (index === 1) {
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.subjectcode = ''
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.subjectname = ''
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.notaxamountCurrency = 0
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.taxCurrency = 0
          this.noTaxAmountOnblur()
        } else if (index === 2) {
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.notaxamountCurrency = 0
          this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.taxCurrency = 0
          this.noTaxAmountOnblur()
        } else if (index === 3) { // 不含税金额
          this.noTaxAmountOnblur()
        } else if (index === 4) { // 税额
          this.taxOnblur()
        }
      } else if (this.pageType === this.pageTypeEnum.approveFee) {
        if (index === 3) { // 不含税金额
          if (this.isMakeCert() === '-1') {
            this.alert(this.getResource('alert.information.yjzzbyxxg')) // 已经制证不允许修改
            return false
          }
          if (!this.approveFeeNoTaxAmountOnblur()) return
        } else if (index === 4) { // 税额
          if (this.isMakeCert() === '-1') {
            this.alert(this.getResource('alert.information.yjzzbyxxg')) // 已经制证不允许修改
            return false
          }
          if (!this.approveFeeTaxOnblur()) return
        }
      }
      if (index === 0) { // 成本中心
        // if (this.gridStatus === 'normal') {
        //   console.log('normal ,not network...')
        //   return
        // }
        let vObj = JSON.parse(v)
        console.log('inner line.......00000成本中心', vObj)
        if (!vObj || vObj.length <= 0) {
          console.log('inner line.......3', vObj)
          this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', { name: 'internalordername', value: [] })
          this.$store.commit('updateDataSscReimburse', { name: 'splitBudgetSubjectList', value: [] })
        } else {
          let param = {}
          param.me = this
          param.queryInternalOrderCode = ''
          param.queryInternalOrderName = ''
          param.companyCode = this.reimbursecompanycode
          param.costingCenterCode = vObj.value
          param.costcenterCode = vObj.value
          param.flag = 'split'
          console.log('inner line.......4', vObj, param)
          this.querySplitInternalOrder(param)
          this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
            name: 'internalordername',
            value: vObj.inwardOrderName
          })
          this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
            name: 'internalordercode',
            value: vObj.inwardOrderCode
          })
        }
      } else if (index === 1) { // 内部订单
        if (this.gridStatus === 'normal') {
          console.log('normal ,not network...')
          return
        }
        let vObj = JSON.parse(v)
        console.log('inner line.......111111内部订单', vObj)
        if (!vObj || vObj.length <= 0 || !vObj.inwardOrderCode) {
          console.log('inner line.......3', vObj)
          this.$store.commit('updateDataSscReimburse', { name: 'splitBudgetSubjectList', value: [] })
        } else {
          let param = {}
          let costcentercode = this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare.costcentercode
          console.log('==============', vObj)
          param.me = this
          param.companyCode = this.reimbursecompanycode
          param.costingCenterCode = costcentercode
          param.inwardOrderCode = vObj.inwardOrderCode
          param.budgetSubjectName = ''
          param.budgetSubjectCode = ''
          param.flag = 'split'
          console.log('inner line.......4', vObj, param)
          this.queryBudgetSubject(param)
          this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
            name: 'internalordername',
            value: vObj.inwardOrderName
          })
          this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
            name: 'internalordercode',
            value: vObj.inwardOrderCode
          })
        }
      } else if (index === 2) {
        let vObj2 = JSON.parse(v)
        console.log('科目编码', vObj2.budgetSubjectCode)
        console.log('科目名称', vObj2.budgetSubjectName)
        vObj2 && this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
          name: 'subjectcode',
          value: vObj2.budgetSubjectCode
        })
        vObj2 && this.$store.commit('updateSelectRowSscReimburseWhBtReimburseCostshare', {
          name: 'subjectname',
          value: vObj2.budgetSubjectName
        })
        console.log('修改后的接口科目', this.$store.state.gridSelectRow.ssc.reimburse.whBtReimburseCostshare)
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
